

import * as Curry from "../../../../../../../node_modules/bs-platform/lib/es6/curry.js";
import * as Sinon from "../../../../../../../node_modules/wonder-bs-sinon/lib/es6_global/src/sinon.js";
import * as Sinon$1 from "sinon";
import * as Wonder_jest from "../../../../../../../node_modules/wonder-bs-jest/lib/es6_global/src/wonder_jest.js";
import * as TestTool$Wonderjs from "../../../../tool/TestTool.js";
import * as GameObjectAPI$Wonderjs from "../../../../../src/api/GameObjectAPI.js";
import * as MainStateTool$Wonderjs from "../../../../tool/service/state/MainStateTool.js";
import * as GameObjectTool$Wonderjs from "../../../../tool/service/gameObject/GameObjectTool.js";
import * as MeshRendererAPI$Wonderjs from "../../../../../src/api/MeshRendererAPI.js";
import * as MeshRendererTool$Wonderjs from "../../../../tool/service/meshRenderer/MeshRendererTool.js";
import * as SparseMapService$WonderCommonlib from "../../../../../../../node_modules/wonder-commonlib/lib/es6_global/src/SparseMapService.js";

describe("MeshRenderer", (function () {
        var sandbox = Sinon.getSandboxDefaultVal(/* () */0);
        var state = /* record */[/* contents */MainStateTool$Wonderjs.createState(/* () */0)];
        var _prepareTwo = function (state) {
          var match = MeshRendererTool$Wonderjs.createBasicMaterialGameObject(state);
          var match$1 = MeshRendererTool$Wonderjs.createBasicMaterialGameObject(match[0]);
          return /* tuple */[
                  match$1[0],
                  match[1],
                  match[2],
                  match$1[1],
                  match$1[2]
                ];
        };
        var _prepareThree = function (state) {
          var match = MeshRendererTool$Wonderjs.createBasicMaterialGameObject(state);
          var match$1 = MeshRendererTool$Wonderjs.createBasicMaterialGameObject(match[0]);
          var match$2 = MeshRendererTool$Wonderjs.createLightMaterialGameObject(match$1[0]);
          return /* tuple */[
                  match$2[0],
                  match[1],
                  match[2],
                  match$1[1],
                  match$1[2],
                  match$2[1],
                  match$2[2]
                ];
        };
        beforeEach((function () {
                sandbox[0] = Sinon$1.sandbox.create();
                state[0] = TestTool$Wonderjs.init(sandbox, undefined, undefined, /* () */0);
                return /* () */0;
              }));
        afterEach((function () {
                return Curry._1(Sinon.restoreSandbox, sandbox[0]);
              }));
        describe("getMeshRendererDrawMode", (function () {
                return Wonder_jest.test("default value is TRIANGLES", (function () {
                              var match = MeshRendererTool$Wonderjs.createBasicMaterialGameObject(state[0]);
                              return Curry._2(Wonder_jest.Expect[/* Operators */23][/* = */5], Wonder_jest.Expect[/* expect */0](MeshRendererAPI$Wonderjs.getMeshRendererDrawMode(match[2], match[0])), MeshRendererTool$Wonderjs.getTriangles(/* () */0));
                            }));
              }));
        describe("setMeshRendererDrawMode", (function () {
                return Wonder_jest.test("set draw mode", (function () {
                              var match = MeshRendererTool$Wonderjs.createBasicMaterialGameObject(state[0]);
                              var meshRenderer1 = match[2];
                              var state$1 = MeshRendererAPI$Wonderjs.setMeshRendererDrawMode(meshRenderer1, MeshRendererTool$Wonderjs.getLines(/* () */0), match[0]);
                              return Curry._2(Wonder_jest.Expect[/* Operators */23][/* = */5], Wonder_jest.Expect[/* expect */0](MeshRendererAPI$Wonderjs.getMeshRendererDrawMode(meshRenderer1, state$1)), MeshRendererTool$Wonderjs.getLines(/* () */0));
                            }));
              }));
        describe("getMeshRendererIsRender", (function () {
                return Wonder_jest.test("default value is render", (function () {
                              var match = MeshRendererTool$Wonderjs.createBasicMaterialGameObject(state[0]);
                              return Curry._2(Wonder_jest.Expect[/* Operators */23][/* = */5], Wonder_jest.Expect[/* expect */0](MeshRendererAPI$Wonderjs.getMeshRendererIsRender(match[2], match[0])), true);
                            }));
              }));
        describe("setMeshRendererIsRender", (function () {
                Wonder_jest.test("set is render", (function () {
                        var match = MeshRendererTool$Wonderjs.createBasicMaterialGameObject(state[0]);
                        var meshRenderer1 = match[2];
                        var state$1 = MeshRendererAPI$Wonderjs.setMeshRendererIsRender(meshRenderer1, false, match[0]);
                        return Curry._2(Wonder_jest.Expect[/* Operators */23][/* = */5], Wonder_jest.Expect[/* expect */0](MeshRendererAPI$Wonderjs.getMeshRendererIsRender(meshRenderer1, state$1)), false);
                      }));
                Wonder_jest.test("if isRender === false, remove from renderArray", (function () {
                        var match = MeshRendererTool$Wonderjs.createBasicMaterialGameObject(state[0]);
                        var state$1 = MeshRendererAPI$Wonderjs.setMeshRendererIsRender(match[2], false, match[0]);
                        return Curry._2(Wonder_jest.Expect[/* Operators */23][/* = */5], Wonder_jest.Expect[/* expect */0](MeshRendererTool$Wonderjs.getBasicMaterialRenderArray(state$1)), /* array */[]);
                      }));
                Wonder_jest.test("if isRender === true, add to renderArray", (function () {
                        var match = MeshRendererTool$Wonderjs.createBasicMaterialGameObject(state[0]);
                        var meshRenderer1 = match[2];
                        var state$1 = MeshRendererAPI$Wonderjs.setMeshRendererIsRender(meshRenderer1, false, match[0]);
                        var state$2 = MeshRendererAPI$Wonderjs.setMeshRendererIsRender(meshRenderer1, true, state$1);
                        return Curry._2(Wonder_jest.Expect[/* Operators */23][/* = */5], Wonder_jest.Expect[/* expect */0](MeshRendererTool$Wonderjs.getBasicMaterialRenderArray(state$2)), /* array */[match[1]]);
                      }));
                describe("test isRender not change", (function () {
                        Wonder_jest.test("test isRender === false", (function () {
                                var match = MeshRendererTool$Wonderjs.createBasicMaterialGameObject(state[0]);
                                var meshRenderer1 = match[2];
                                var state$1 = MeshRendererAPI$Wonderjs.setMeshRendererIsRender(meshRenderer1, false, match[0]);
                                var state$2 = MeshRendererAPI$Wonderjs.setMeshRendererIsRender(meshRenderer1, false, state$1);
                                return Curry._2(Wonder_jest.Expect[/* Operators */23][/* = */5], Wonder_jest.Expect[/* expect */0](MeshRendererTool$Wonderjs.getBasicMaterialRenderArray(state$2)), /* array */[]);
                              }));
                        return Wonder_jest.test("test isRender === true", (function () {
                                      var match = MeshRendererTool$Wonderjs.createBasicMaterialGameObject(state[0]);
                                      var meshRenderer1 = match[2];
                                      var state$1 = MeshRendererAPI$Wonderjs.setMeshRendererIsRender(meshRenderer1, true, match[0]);
                                      var state$2 = MeshRendererAPI$Wonderjs.setMeshRendererIsRender(meshRenderer1, true, state$1);
                                      return Curry._2(Wonder_jest.Expect[/* Operators */23][/* = */5], Wonder_jest.Expect[/* expect */0](MeshRendererTool$Wonderjs.getBasicMaterialRenderArray(state$2)), /* array */[match[1]]);
                                    }));
                      }));
                return /* () */0;
              }));
        describe("getBasicMaterialRenderArray", (function () {
                return Wonder_jest.test("get array of gameObject which has meshRenderer component and basicMaterial component", (function () {
                              var match = _prepareThree(state[0]);
                              return Curry._2(Wonder_jest.Expect[/* Operators */23][/* = */5], Wonder_jest.Expect[/* expect */0](MeshRendererTool$Wonderjs.getBasicMaterialRenderArray(match[0])), /* array */[
                                          match[1],
                                          match[3]
                                        ]);
                            }));
              }));
        describe("getLightMaterialRenderArray", (function () {
                return Wonder_jest.test("get array of gameObject which has meshRenderer component and lightMaterial component", (function () {
                              var match = _prepareThree(state[0]);
                              return Curry._2(Wonder_jest.Expect[/* Operators */23][/* = */5], Wonder_jest.Expect[/* expect */0](MeshRendererTool$Wonderjs.getLightMaterialRenderArray(match[0])), /* array */[match[5]]);
                            }));
              }));
        describe("test add component", (function () {
                describe("should add meshRenderer component after add material component", (function () {
                        Wonder_jest.test("test basic material", (function () {
                                var match = MeshRendererAPI$Wonderjs.createMeshRenderer(state[0]);
                                var meshRenderer = match[1];
                                var match$1 = GameObjectAPI$Wonderjs.createGameObject(match[0]);
                                var gameObject = match$1[1];
                                var state$1 = match$1[0];
                                return Wonder_jest.Expect[/* toThrowMessage */20]("should add material component before add meshRenderer component", Wonder_jest.Expect[/* expect */0]((function () {
                                                  GameObjectAPI$Wonderjs.addGameObjectMeshRendererComponent(gameObject, meshRenderer, state$1);
                                                  return /* () */0;
                                                })));
                              }));
                        return Wonder_jest.test("test light material", (function () {
                                      var match = MeshRendererAPI$Wonderjs.createMeshRenderer(state[0]);
                                      var meshRenderer = match[1];
                                      var match$1 = GameObjectAPI$Wonderjs.createGameObject(match[0]);
                                      var gameObject = match$1[1];
                                      var state$1 = match$1[0];
                                      return Wonder_jest.Expect[/* toThrowMessage */20]("should add material component before add meshRenderer component", Wonder_jest.Expect[/* expect */0]((function () {
                                                        GameObjectAPI$Wonderjs.addGameObjectMeshRendererComponent(gameObject, meshRenderer, state$1);
                                                        return /* () */0;
                                                      })));
                                    }));
                      }));
                return /* () */0;
              }));
        describe("disposeComponent", (function () {
                describe("dispose data", (function () {
                        Wonder_jest.test("remove from gameObjectMap", (function () {
                                var match = MeshRendererTool$Wonderjs.createBasicMaterialGameObject(state[0]);
                                var meshRenderer1 = match[2];
                                var state$1 = GameObjectTool$Wonderjs.disposeGameObjectMeshRendererComponent(match[1], meshRenderer1, match[0]);
                                var match$1 = MeshRendererTool$Wonderjs.getRecord(state$1);
                                return Curry._2(Wonder_jest.Expect[/* Operators */23][/* = */5], Wonder_jest.Expect[/* expect */0](SparseMapService$WonderCommonlib.has(meshRenderer1, match$1[/* gameObjectMap */6])), false);
                              }));
                        describe("remove from basicMaterialRenderGameObjectArray", (function () {
                                Wonder_jest.test("test getBasicMaterialRenderArray", (function () {
                                        var match = _prepareTwo(state[0]);
                                        var state$1 = GameObjectTool$Wonderjs.disposeGameObjectMeshRendererComponent(match[1], match[2], match[0]);
                                        return Curry._2(Wonder_jest.Expect[/* Operators */23][/* = */5], Wonder_jest.Expect[/* expect */0](MeshRendererTool$Wonderjs.getBasicMaterialRenderArray(state$1)), /* array */[match[3]]);
                                      }));
                                return Wonder_jest.test("test add gameObject after dispose", (function () {
                                              var match = MeshRendererTool$Wonderjs.createBasicMaterialGameObject(state[0]);
                                              var state$1 = GameObjectTool$Wonderjs.disposeGameObjectMeshRendererComponent(match[1], match[2], match[0]);
                                              var match$1 = MeshRendererTool$Wonderjs.createBasicMaterialGameObject(state$1);
                                              return Curry._2(Wonder_jest.Expect[/* Operators */23][/* = */5], Wonder_jest.Expect[/* expect */0](MeshRendererTool$Wonderjs.getBasicMaterialRenderArray(match$1[0])), /* array */[match$1[1]]);
                                            }));
                              }));
                        describe("remove from lightMaterialRenderGameObjectArray", (function () {
                                var _prepare = function (state) {
                                  var match = MeshRendererTool$Wonderjs.createBasicMaterialGameObject(state);
                                  var match$1 = MeshRendererTool$Wonderjs.createLightMaterialGameObject(match[0]);
                                  var match$2 = MeshRendererTool$Wonderjs.createLightMaterialGameObject(match$1[0]);
                                  return /* tuple */[
                                          match$2[0],
                                          match[1],
                                          match[2],
                                          match$1[1],
                                          match$1[2],
                                          match$2[1],
                                          match$2[2]
                                        ];
                                };
                                Wonder_jest.test("test getLightMaterialRenderArray", (function () {
                                        var match = _prepare(state[0]);
                                        var state$1 = GameObjectTool$Wonderjs.disposeGameObjectMeshRendererComponent(match[3], match[4], match[0]);
                                        return Curry._2(Wonder_jest.Expect[/* Operators */23][/* = */5], Wonder_jest.Expect[/* expect */0](MeshRendererTool$Wonderjs.getLightMaterialRenderArray(state$1)), /* array */[match[5]]);
                                      }));
                                return Wonder_jest.test("test add gameObject after dispose", (function () {
                                              var match = _prepare(state[0]);
                                              var state$1 = GameObjectTool$Wonderjs.disposeGameObjectMeshRendererComponent(match[3], match[4], match[0]);
                                              var match$1 = MeshRendererTool$Wonderjs.createLightMaterialGameObject(state$1);
                                              return Curry._2(Wonder_jest.Expect[/* Operators */23][/* = */5], Wonder_jest.Expect[/* expect */0](MeshRendererTool$Wonderjs.getLightMaterialRenderArray(match$1[0])), /* array */[
                                                          match$1[1],
                                                          match[5]
                                                        ]);
                                            }));
                              }));
                        describe("test remove from type array", (function () {
                                Wonder_jest.test("remove from drawModes", (function () {
                                        var match = MeshRendererTool$Wonderjs.createLightMaterialGameObject(state[0]);
                                        var meshRenderer1 = match[2];
                                        var match$1 = MeshRendererTool$Wonderjs.createLightMaterialGameObject(match[0]);
                                        var meshRenderer2 = match$1[2];
                                        var drawMode1 = MeshRendererTool$Wonderjs.getPoints(/* () */0);
                                        var drawMode2 = MeshRendererTool$Wonderjs.getLines(/* () */0);
                                        var state$1 = MeshRendererAPI$Wonderjs.setMeshRendererDrawMode(meshRenderer1, drawMode1, match$1[0]);
                                        var state$2 = MeshRendererAPI$Wonderjs.setMeshRendererDrawMode(meshRenderer2, drawMode2, state$1);
                                        var state$3 = GameObjectTool$Wonderjs.disposeGameObjectMeshRendererComponent(match[1], meshRenderer1, state$2);
                                        TestTool$Wonderjs.closeContractCheck(/* () */0);
                                        return Curry._2(Wonder_jest.Expect[/* Operators */23][/* = */5], Wonder_jest.Expect[/* expect */0](/* tuple */[
                                                        MeshRendererAPI$Wonderjs.getMeshRendererDrawMode(meshRenderer1, state$3),
                                                        MeshRendererAPI$Wonderjs.getMeshRendererDrawMode(meshRenderer2, state$3)
                                                      ]), /* tuple */[
                                                    MeshRendererTool$Wonderjs.getDefaultDrawMode(/* () */0),
                                                    drawMode2
                                                  ]);
                                      }));
                                return Wonder_jest.test("remove from isRenders", (function () {
                                              var match = MeshRendererTool$Wonderjs.createLightMaterialGameObject(state[0]);
                                              var meshRenderer1 = match[2];
                                              var match$1 = MeshRendererTool$Wonderjs.createLightMaterialGameObject(match[0]);
                                              var meshRenderer2 = match$1[2];
                                              var isRender1 = !MeshRendererTool$Wonderjs.getDefaultIsRender(/* () */0);
                                              var isRender2 = !MeshRendererTool$Wonderjs.getDefaultIsRender(/* () */0);
                                              var state$1 = MeshRendererAPI$Wonderjs.setMeshRendererIsRender(meshRenderer1, isRender1, match$1[0]);
                                              var state$2 = MeshRendererAPI$Wonderjs.setMeshRendererIsRender(meshRenderer2, isRender2, state$1);
                                              var state$3 = GameObjectTool$Wonderjs.disposeGameObjectMeshRendererComponent(match[1], meshRenderer1, state$2);
                                              TestTool$Wonderjs.closeContractCheck(/* () */0);
                                              return Curry._2(Wonder_jest.Expect[/* Operators */23][/* = */5], Wonder_jest.Expect[/* expect */0](/* tuple */[
                                                              MeshRendererAPI$Wonderjs.getMeshRendererIsRender(meshRenderer1, state$3),
                                                              MeshRendererAPI$Wonderjs.getMeshRendererIsRender(meshRenderer2, state$3)
                                                            ]), /* tuple */[
                                                          MeshRendererTool$Wonderjs.getDefaultIsRender(/* () */0),
                                                          isRender2
                                                        ]);
                                            }));
                              }));
                        return /* () */0;
                      }));
                Wonder_jest.test("the disposed meshRenderer shouldn't affect other alive ones' record", (function () {
                        var match = _prepareTwo(state[0]);
                        var state$1 = GameObjectTool$Wonderjs.disposeGameObjectMeshRendererComponent(match[1], match[2], match[0]);
                        return Curry._2(Wonder_jest.Expect[/* Operators */23][/* = */5], Wonder_jest.Expect[/* expect */0](MeshRendererAPI$Wonderjs.unsafeGetMeshRendererGameObject(match[4], state$1)), match[3]);
                      }));
                describe("test add new one after dispose old one", (function () {
                        Wonder_jest.test("use disposed index as new index firstly", (function () {
                                var match = _prepareTwo(state[0]);
                                var meshRenderer1 = match[2];
                                var state$1 = GameObjectTool$Wonderjs.disposeGameObjectMeshRendererComponent(match[1], meshRenderer1, match[0]);
                                var match$1 = MeshRendererAPI$Wonderjs.createMeshRenderer(state$1);
                                return Curry._2(Wonder_jest.Expect[/* Operators */23][/* = */5], Wonder_jest.Expect[/* expect */0](match$1[1]), meshRenderer1);
                              }));
                        return Wonder_jest.test("if has no disposed index, get index from meshRendererRecord.index", (function () {
                                      var match = _prepareTwo(state[0]);
                                      var meshRenderer2 = match[4];
                                      var state$1 = GameObjectTool$Wonderjs.disposeGameObjectMeshRendererComponent(match[3], meshRenderer2, match[0]);
                                      var match$1 = MeshRendererAPI$Wonderjs.createMeshRenderer(state$1);
                                      var match$2 = MeshRendererAPI$Wonderjs.createMeshRenderer(match$1[0]);
                                      return Curry._2(Wonder_jest.Expect[/* Operators */23][/* = */5], Wonder_jest.Expect[/* expect */0](/* tuple */[
                                                      match$1[1],
                                                      match$2[1]
                                                    ]), /* tuple */[
                                                  meshRenderer2,
                                                  meshRenderer2 + 1 | 0
                                                ]);
                                    }));
                      }));
                describe("contract check", (function () {
                        return Wonder_jest.test("expect dispose the alive component, but actual not", (function () {
                                      var match = _prepareTwo(state[0]);
                                      var meshRenderer1 = match[2];
                                      var gameObject1 = match[1];
                                      var state$1 = GameObjectTool$Wonderjs.disposeGameObjectMeshRendererComponent(gameObject1, meshRenderer1, match[0]);
                                      return Wonder_jest.Expect[/* toThrowMessage */20]("expect dispose the alive component, but actual not", Wonder_jest.Expect[/* expect */0]((function () {
                                                        GameObjectTool$Wonderjs.disposeGameObjectMeshRendererComponent(gameObject1, meshRenderer1, state$1);
                                                        return /* () */0;
                                                      })));
                                    }));
                      }));
                return /* () */0;
              }));
        describe("contract check: is alive", (function () {
                describe("if meshRenderer is disposed", (function () {
                        return Wonder_jest.test("unsafeGetMeshRendererGameObject should error", (function () {
                                      var match = MeshRendererTool$Wonderjs.createBasicMaterialGameObject(state[0]);
                                      var meshRenderer1 = match[2];
                                      var state$1 = GameObjectTool$Wonderjs.disposeGameObjectMeshRendererComponent(match[1], meshRenderer1, match[0]);
                                      return Wonder_jest.Expect[/* toThrowMessage */20]("expect component alive, but actual not", Wonder_jest.Expect[/* expect */0]((function () {
                                                        return MeshRendererAPI$Wonderjs.unsafeGetMeshRendererGameObject(meshRenderer1, state$1);
                                                      })));
                                    }));
                      }));
                return /* () */0;
              }));
        return /* () */0;
      }));

export {
  
}
/*  Not a pure module */
